Skip to content

Conversation

@wikumChamith
Copy link
Member

@wikumChamith wikumChamith commented May 30, 2025

@wikumChamith wikumChamith marked this pull request as draft May 30, 2025 06:12
@wikumChamith wikumChamith changed the title Report-912: Update to OpenMRS platform 2.7.3 and Support Java 21 REPORT-912: Update to OpenMRS platform 2.7.3 and Support Java 21 May 30, 2025
@dkayiwa
Copy link
Member

dkayiwa commented May 30, 2025

Can we add include the other Java versions in the build?

//import org.openmrs.util.OpenmrsUtil;
//
///**
// * The logic that evaluates a {@link DataExportDataSetDefinition} and produces a {@link DataSet}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a deprecated class. So I am deleting this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you see the above comment?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Sorry, my mistake. I am working on this.

return x != null && x.equals(y);
}

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these formatting changes?

Copy link
Member Author

@wikumChamith wikumChamith May 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replaced this with PropertiesType in api-2.4. We have to remove this when removing the sub-module.

https://github.com/openmrs/openmrs-module-reporting/blob/master/api-2.4/src/main/java/org/openmrs/module/reporting/report/service/db/PropertiesType.java

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before removing the submodule, can we avoid touching this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dkayiwa We need to update the nullSafeGet and nullSafeSet methods; without doing so, the code won't compile. I reverted the file temporarily, and as you can see from the build, it's failing with compile errors:
https://github.com/openmrs/openmrs-module-reporting/actions/runs/15436424952/job/43443786399

assertThat(persistedDefinition, notNullValue());
assertThat(persistedDefinition.getName(), is("Patients in 2006 by indicators"));
assertThat(persistedDefinition.getSpecifications(), not(empty()));
// executeDataSet("org/openmrs/module/reporting/include/DefinitionServiceTest.xml");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a deprecated class. So I am deleting this.

//import org.openmrs.reporting.export.DataExportReportObject;
//import org.openmrs.test.BaseModuleContextSensitiveTest;
//import org.openmrs.test.StartModule;
//
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a deprecated class. So I am deleting this.

/**
* @see UserType#equals(Object, Object)
*/
public boolean equals(Object x, Object y) throws HibernateException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting changes again?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just replaced this with ReportDefinitionType in api-2.4. We have to remove this when removing the sub-module.

https://github.com/openmrs/openmrs-module-reporting/blob/master/api-2.4/src/main/java/org/openmrs/module/reporting/report/service/db/ReportDefinitionType.java

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just do not seem to understand what is going on here. I see it deleted and added back in the same file.

import org.hibernate.usertype.CompositeUserType;
import org.hibernate.usertype.UserType;
import org.openmrs.module.reporting.common.HibernateUtil;
import org.openmrs.module.reporting.report.renderer.RenderingMode;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting changes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just replaced this with RenderingModeType in api-2.4. We have to remove this when removing the sub module.

@wikumChamith wikumChamith requested a review from dkayiwa May 30, 2025 11:47
api-1.9/pom.xml Outdated
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>reportingcompatibility-api</artifactId>
<version>3.0.0-SNAPSHOT</version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you forget to add scope here?

/**
* @see UserType#assemble(Serializable, Object)
*/
public Object assemble(Serializable cached, Object owner) throws HibernateException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there where you added it after deleting it from the above?

public class RenderingModeType implements CompositeUserType {

/**
* @see CompositeUserType#returnedClass()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this deleting and then adding it back as new?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dkayiwa, what's happening here is that method signatures like nullSafeGet have changed in newer platform versions. Specifically:

CompositeUserType#nullSafeGet(ResultSet, String[], SharedSessionContractImplementor, Object)

has been updated to:

CompositeUserType#nullSafeGet(ResultSet, String[], SharedSessionContractImplementor, Object)

Previously, I took a shortcut by copying these classes from the 2.4 branch, since we're planning to remove these classes when we eventually merge the legacy submodules. I've now updated the PR to avoid confusion.

Comment on lines 120 to 141
public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException {
String parameterizableUuid = (String) HibernateUtil.standardType("STRING").nullSafeGet(rs, names[0], session, owner);
if (StringUtils.isEmpty(parameterizableUuid)) { return null; }
String serializedMappings = (String) HibernateUtil.standardType("STRING").nullSafeGet(rs, names[1], session, owner);
Definition d = DefinitionContext.getDefinitionByUuid(mappedType, parameterizableUuid);
Map<String, Object> mappings = new HashMap<String, Object>();
if (StringUtils.isNotBlank(serializedMappings)) {
try {
mappings = Context.getSerializationService().deserialize(serializedMappings, Map.class, ReportingSerializer.class);
}
catch (Exception e) {
throw new HibernateException("Unable to deserialize parameter mappings for definition", e);
}
}
return new Mapped(d, mappings);
}

/**
* @see CompositeUserType#nullSafeSet(PreparedStatement, Object, int, SharedSessionContractImplementor)
*/
public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException {
String definitionUuid = null;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why GitHub is showing this as a completely new file. The only thing I did was change these methods :).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When comparing these changes locally, I am not seeing this issue.

@wikumChamith wikumChamith requested a review from dkayiwa May 30, 2025 14:47
api/pom.xml Outdated
<groupId>org.openmrs.module</groupId>
<artifactId>reportingcompatibility-api</artifactId>
<version>${reportingCompatibilityVersion}</version>
<scope>provided</scope>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change this scope?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am getting an error with the 'provided' scope.

java.lang.IllegalStateException: Failed to load ApplicationContext
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:98)
	at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:124)
	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:118)
	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
	at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:248)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:227)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:246)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataExportDataSetDefinitionPersister': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.openmrs.module.reporting.dataset.definition.persister.DataExportDataSetDefinitionPersister] from ClassLoader [sun.misc.Launcher$AppClassLoader@75b84c92]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:298)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1302)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1219)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:921)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:127)
	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
	at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:276)
	at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:244)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:141)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:90)
	... 12 more
Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.openmrs.module.reporting.dataset.definition.persister.DataExportDataSetDefinitionPersister] from ClassLoader [sun.misc.Launcher$AppClassLoader@75b84c92]
	at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:485)
	at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:321)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:276)
	... 29 more
Caused by: java.lang.NoClassDefFoundError: org/openmrs/reporting/AbstractReportObject
	at java.lang.Class.getDeclaredMethods0(Native Method)
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2729)
	at java.lang.Class.getDeclaredMethods(Class.java:2003)
	at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:467)
	... 31 more
Caused by: java.lang.ClassNotFoundException: org.openmrs.reporting.AbstractReportObject
	at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
	... 35 more

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't have this scope changed from provided to compile.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't have this scope changed from provided to compile.

@mseaton, do you know why this error is occurring?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes @wikumChamith . Currently, this class is in the api-1.9 maven submodule, which builds against OpenMRS 1.9 and is only conditionally loaded by OpenMRS if the core version is 1.9-1.12:

		<conditionalResource>
			<path>/lib/reporting-api-1.9.*</path>
			<openmrsVersion>1.9.9 - 1.12.*</openmrsVersion>
		</conditionalResource>

Now that you are trying to move this class into the main api maven submodule and have it build against OpenMRS 2.x, it is failing because the classes that it depends upon are no longer in core, but only found in the reportingcompatibility module.

Best thing to do is to try to get the DataExportDataSetEvaluator and DataExportDataSetDefinitionPersister to be conditionally loaded only if the reportingcompatibility module is running, and to make reportingcompatibility an aware-of dependency in config.xml, and a provided dependency in the pom, but I'm not sure that's possible to do with the Handler annotation.

We might also just remove support for these constructs from the reporting module, since I'm not confident that anyone actually ever used them, and it is even more likely that no one is currently using them.

@dkayiwa / @ibacher ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am in favour of removing them to make things simpler. If any one ever complains about them, we can then look into bringing them back.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing those two classes fixed the issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great - can you remove the reportingcompatibility dependency entirely then?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed it.

@wikumChamith wikumChamith requested a review from dkayiwa June 3, 2025 10:31
@wikumChamith wikumChamith force-pushed the REPORT-912 branch 5 times, most recently from 7d3a450 to 88d0b8b Compare June 4, 2025 07:36
@dkayiwa
Copy link
Member

dkayiwa commented Jun 4, 2025

@wikumChamith would it require as many changes if we simply changed the platform version to 2.4.0?

You can clearly see that iam trying to do a step by step upgrade in order to limit the number of changes, especially for these complicated modules. 😊

@wikumChamith
Copy link
Member Author

@wikumChamith would it require as many changes if we simply changed the platform version to 2.4.0?

You can clearly see that iam trying to do a step by step upgrade in order to limit the number of changes, especially for these complicated modules. 😊

@dkayiwa PR for 2.4 update: #262

@wikumChamith wikumChamith marked this pull request as ready for review June 11, 2025 07:46
@wikumChamith wikumChamith force-pushed the REPORT-912 branch 2 times, most recently from e68ddeb to 1179b0f Compare June 11, 2025 07:55
@wikumChamith wikumChamith requested review from ibacher and mseaton June 11, 2025 09:07
@wikumChamith
Copy link
Member Author

@dkayiwa This is now ready to review.

Copy link
Member

@mseaton mseaton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments. We cannot change module dependencies from provided to compile scope.

Copy link
Member

@Ruhanga Ruhanga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this is looking good — thanks @wikumChamith! I have a few suggestions that I believe would be a good fit to include in this PR.

@wikumChamith
Copy link
Member Author

@Ruhanga, I’ve migrated the tests I touched in this PR to use Jupiter BaseModuleContextSensitiveTest. But if we’re planning to migrate all the tests in the module, I think it’s better to create a separate ticket.

@Ruhanga
Copy link
Member

Ruhanga commented Jul 7, 2025

Correct and thanks @wikumChamith for the nice work.

Copy link
Member

@Ruhanga Ruhanga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

I guess we might need a release before this can get merged in. Any objections or recommendations @mseaton, @dkayiwa

@mseaton
Copy link
Member

mseaton commented Jul 7, 2025

LGTM!

I guess we might need a release before this can get merged in. Any objections or recommendations @mseaton, @dkayiwa

Releasing existing version now.

Copy link
Member

@Ruhanga Ruhanga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with this. Any objections to having this merged in dear reviewers, @dkayiwa, @mseaton, @ibacher?

Copy link
Member

@mseaton mseaton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks!

*/
@TestExecutionListeners(OpenmrsVersionTestListener.class)
@RequiresVersion("2.4.* - 2.*")
public class EvaluationProfilerTest24On extends BaseModuleContextSensitiveTest {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did we remove this class?

PowerMockito.when(Context.hasPrivilege(DOES_NOT_HAVE_PRIV)).thenReturn(false);
initializeInMemoryDatabase();
executeDataSet("org/openmrs/module/reporting/include/PrivilegeTest.xml");
Context.logout();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to log out and authenticate?

@wikumChamith
Copy link
Member Author

@dkayiwa I updated the PR.

@dkayiwa dkayiwa merged commit 2c8e57e into openmrs:master Jul 24, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants